<?php
namespace app\index\controller;
use think\Db;
class About extends Base{
    public function aboutus(){
        $customer=Db::name('customer')->where('id',input("param.cus_id"))->find();
    	$navs=Db::name('nav')->where('nav_type',3)->where('cus_id',input("param.cus_id"))->where('state',1)->order('sort asc')->select();
    	$logo=Db::name('aboutus')->where('cus_id',input("param.cus_id"))->find();
        $banner=Db::name('banner')->where('cus_id',input("param.cus_id"))->where('state',1)->where('mtype',4)->order('sort desc')->find();
        $this->assign('cus_id',input("param.cus_id"));
        $this->assign('customer',$customer);
        $this->assign('navs',$navs);
        // $this->assign('url','http://'.$_SERVER['HTTP_HOST'].'/index.php/index/');
        $this->assign('url','/index.php/index/');
        $this->assign('logo',$logo);
        $this->assign('banner',$banner);
        return $this->fetch();
    }
    public function contactus(){
        $customer=Db::name('customer')->where('id',input("param.cus_id"))->find();
    	$navs=Db::name('nav')->where('nav_type',3)->where('cus_id',input("param.cus_id"))->where('state',1)->order('sort asc')->select();
    	$logo=Db::name('aboutus')->where('cus_id',input("param.cus_id"))->find();
        $banner=Db::name('banner')->where('cus_id',input("param.cus_id"))->where('state',1)->where('mtype',5)->order('sort desc')->find();
        if($logo['coordinates']!=''){
            $coordinates=explode(",",$logo['coordinates']);
        }else{
            $coordinates[0]=30.530180;
            $coordinates[1]=114.341412;
        }
        $this->assign('cus_id',input("param.cus_id"));
        $this->assign('customer',$customer);
        $this->assign('navs',$navs);
        // $this->assign('url','http://'.$_SERVER['HTTP_HOST'].'/index.php/index/');
        $this->assign('url','/index.php/index/');
        $this->assign('logo',$logo);
        $this->assign('coordinates',$coordinates);
        $this->assign('banner',$banner);
        return $this->fetch();
    }
    public function message(){
        $param = input('post.');
        $data['cus_id']=$param['cus_id'];
        $data['name']=$param['name'];
        $data['tel']=$param['tel'];
        $data['email']=$param['email'];
        $data['message']=$param['message'];
        $data['time']=time();
        $res=Db::name('message')->insert($data);
        if($res){
            return json(['code' => 200,'msg' => '提交成功！']);
        }else{
            return json(['code' => 500,'msg' => '提交失败!']);
        }
    }
    public function singlepage(){
        $customer=Db::name('customer')->where('id',input("param.cus_id"))->find();
        $navs=Db::name('nav')->where('nav_type',3)->where('cus_id',input("param.cus_id"))->where('state',1)->order('sort asc')->select();
        $logo=Db::name('aboutus')->where('cus_id',input("param.cus_id"))->find();
        $banner=Db::name('banner')->where('cus_id',input("param.cus_id"))->where('state',1)->where('mtype',4)->order('sort desc')->find();
        $detail=Db::name('single')->where('cus_id',input("param.cus_id"))->where('id',input("param.single"))->find();
        $this->assign('cus_id',input("param.cus_id"));
        $this->assign('customer',$customer);
        $this->assign('navs',$navs);
        // $this->assign('url','http://'.$_SERVER['HTTP_HOST'].'/index.php/index/');
        $this->assign('url','/index.php/index/');
        $this->assign('logo',$logo);
        $this->assign('banner',$banner);
        $this->assign('detail',$detail);
        $this->assign('single',input("param.single"));
        return $this->fetch();
    }
}
